package com.my.ext.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.my.ext.entity.Admin;
import com.my.ext.entity.Org;
import com.my.ext.mapper.AdminMapper;
import com.my.ext.mapper.OrgMapper;
import com.my.ext.service.IOrgService;

@Service
public class OrgService implements IOrgService{

	@Autowired
	OrgMapper mapper;
	
	@Autowired
	AdminMapper adminMapper;
	
	@Override
	public PageInfo<Org> findAllOrgs(int page, int size) {
		PageHelper.startPage(page, size);
		PageInfo<Org> result = new PageInfo<>(mapper.findByPage());
		
		return result;
	}

	@Override
	public int saveOrg(Org org, Admin admin) {
		mapper.saveOrg(org);
		adminMapper.saveAdmin(admin);
		mapper.saveRelation(admin.getId(), org.getId());
		return 1;
	}

	@Override
	public Org findOrgByAdmin(Admin admin) {
		return mapper.findByAdmin(admin);
	}

	@Override
	public Org findOrgById(int id) {
		return mapper.findOrgByID(id);
	}

}
